<?php
/**
 *
 * User: wufeng
 * Date: 2020/06/08
 */

namespace app\admin\command;
use app\models\StudentModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;

class Visit extends Command
{
	/**
	 * modify by wufeng
	 * Date: 2020/06/09
	 *
	 * @param $val
	 * @param $output
	 */
	public function visitStatus($val, $output)
	{
		$val = $val.''.date('H:i:s');
		$visiting_timestamps = (new StudentModel())->column('visiting_timestamp');
		$startDateStrtotime = strtotime($val) ? strtotime($val) : strtotime(date('Y-m-d H:i:s', strtotime('-1 day')));
		$where = [];
		$where['follow_up']  = 36;
		$where['is_audition']  = ['in','0,1'];
		$where['status'] = 1;
		foreach ($visiting_timestamps as $visiting_timestamp){
			if($startDateStrtotime > $visiting_timestamp){
				(new StudentModel())
					->where($where)
					->update(['follow_up'=>-1]);
			}
			$output->writeln(date('Y-m-d H:i:s', $visiting_timestamp).'-'.date('Y-m-d H:i:s', $startDateStrtotime));
		}

		$output->writeln('执行完成：'.date('Y-m-d h:i:s'));
	}

	/**
	 * modify by wufeng
	 * Date: 2020/06/09
	 *
	 */
	protected function configure()
	{
		$this->setName('Visit')
			->addOption('function', 'f', Option::VALUE_REQUIRED, 'function name', null)
			->addOption('value', 'a', Option::VALUE_REQUIRED, 'value name', null)
			->setDescription('Here is the PTS ');
	}

	/**
	 * modify by wufeng
	 * Date: 2020/06/09
	 *
	 * @param Input $input
	 * @param Output $output
	 * @return int|void|null
	 */
	protected function execute(Input $input, Output $output)
	{
		$functionName = $input->getOption('function') ?: '';
		$value = $input->getOption('value') ?: '';
		$this->{$functionName}($value, $output);
		$output->writeln('执行完成：'.date('Y-m-d h:i:s'));
	}
}